<?php
class Page {
	private $__config;
	private $url; 
	private $movieURL;
	private $mapID;
	function __construct($config){
		$this->__config = &$config;
		$this->url = trim($_GET["url"]);
		$this->movieURL = trim($_GET["murl"]);
		$this->mapID = trim($_GET["mID"]);
	}
	
	function __destruct(){
		
	}
	
	private function JobStartAsync($url)
	{
		$opts = array(
			  'http'=>array(
			    'method'=>"GET",
			    'header'=>"Accept-language: en\r\n"
			  )
			);
			
			$context = stream_context_create($opts);
			
			// Open the file using the HTTP headers set above
			$file = file_get_contents($url, false, $context);
			return $file;
	}
	
	
	public function toString(){
		if (!isset($this->url) && !isset($this->movieURL)){
			return "FAIL";
		}
		$host = $this->__config->get("DB")->get("DBHOST");
		$usr  = $this->__config->get("DB")->get("USER");
		$dbname = $this->__config->get("DB")->get("DBNAME");
		$pass = $this->__config->get("DB")->get("PASS");
		$conn = mysql_connect($host, $usr, $pass);
		mysql_select_db($dbname);
		if ($this->url != "" && $this->movieURL ==""){
			$sql = "SELECT COUNT(*) TOPLAM FROM tbl_sitemaps WHERE url='".$this->url."'";
			$q = mysql_query($sql);
			$data = mysql_fetch_array($q);
			$res ="EXIST";
			if ($data["TOPLAM"] == 0){
				$sql = "insert into tbl_sitemaps(url) values ('".$this->url."')";
				mysql_query($sql);
				$sql = "select id from tbl_sitemaps order by id desc";
				$q = mysql_query($sql);
				$data = mysql_fetch_array($q);
				
				$res = "OK";
			}
		} else {
			$res= "FAIL";
		}
		mysql_close($conn);
		return $res;
	}
}
?>